    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <!-- 引入 layui.css -->
        <link href="//unpkg.com/layui@2.8.0/dist/css/layui.css" rel="stylesheet">
        <!-- 引入 layui.js -->
        <script src="//unpkg.com/layui@2.8.0/dist/layui.js"></script>
    </head>
    <body>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>核价单</legend>
    </fieldset>
    <div class="layui-form" action="form.html">
            <%--报价单表格--%>
                <%--<div class="layui-inline">--%>
                    <%--<label class="layui-form-label">品牌</label>--%>
                    <%--<div class="layui-input-inline"><input type="text" name="brand" lay-verify="required"--%>
                                                           <%--placeholder="品牌" class="layui-input layui-disabled" readonly>--%>
                    <%--</div>--%>
                <%--</div>--%>
            <form action="" id="form-verifyPrice">
            <div class="layui-form-item">
                <label class="layui-form-label">款号</label>
                <div class="layui-input-inline" style="width: 300px">
                    <input type="hidden" id="styleNumberId" name="styleNumberId">
                    <select id="styleNumber" name="styleNumber" lay-verify="required" lay-filter="styleNumber" lay-search >
                        <option value="-1">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">报价工厂</label>
                    <div class="layui-input-inline"><input type="text" name="quotationFactory" lay-verify="required"
                                                           class="layui-input layui-disabled" value="韩舜捷服饰有限公司" readonly></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">货号</label>
                    <div class="layui-input-inline"><input type="text" name="itemNumber" lay-verify="required"
                                                           placeholder="货号" class="layui-input ">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">品牌</label>
                    <div class="layui-input-inline"><input type="text" name="brand" lay-verify="required"
                                                           placeholder="品牌" class="layui-input layui-disabled" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">合同数量</label>
                    <div class="layui-input-inline"><input type="text" name="orderNumber" lay-verify="required"
                                                           placeholder="合同数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">预计返件(件)</label>
                    <div class="layui-input-inline"><input type="text" name="predictReorder" lay-verify="required"
                                                           placeholder="预计返单" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">生产周期(天)</label>
                    <div class="layui-input-inline"><input type="text" name="productionCycle" lay-verify="required"
                                                           placeholder="生产周期" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">面料储备</label>
                    <input type="radio" name="clothStore" value="0" title="默认" checked="checked">
                    <div lay-radio>
                        <span style="color: blue;">有</span>
                    </div>
                    <input type="radio" name="clothStore" value="1" title="默认">
                    <div lay-radio>
                        <span style="color: pink;">否</span>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">生产工厂</label>
                    <div class="layui-input-inline">
                        <input type="text" name="factoryName" lay-verify="required" value="韩舜捷服饰有限公司" readonly class="layui-input layui-disabled">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">生产负责人</label>
                    <div class="layui-input-inline">
                        <input readonly="true" type="text" name="factoryPrincipal" lay-verify="required" placeholder="魏佳诚" class="layui-input layui-disabled"value="魏佳诚" readonly >
                    </div>
                </div>
            </div>
        </form>
            <%--物料表格--%>
            <%--<form action="" id="form-materials">--%>
                <%--<fieldset class="layui-elem-field layui-field-title">--%>
                    <%--<legend>面辅料</legend>--%>
                <%--</fieldset>--%>
                <%--<div class="layui-form-item">--%>
                    <%--<label class="layui-form-label">面辅料种类</label>--%>
                    <%--<div class="layui-input-block">--%>
                        <%--<input type="checkbox"  name="arr1[0]" lay-skin="tag" title="面料" data-target="content1">--%>
                        <%--<input type="checkbox"  name="arr1[1]" lay-skin="tag" title="羽绒" data-target="content2">--%>
                        <%--<input type="checkbox"  name="arr1[2]" lay-skin="tag" title="毛领" data-target="content3">--%>
                        <%--<input type="checkbox"  name="arr1[3]" lay-skin="tag" title="棉" data-target="content4">--%>
                        <%--<input type="checkbox"  name="arr1[4]" lay-skin="tag" title="辅料" data-target="content5">--%>
                        <%--<input type="checkbox"  name="arr1[5]" lay-skin="tag" title="标准辅料" data-target="content6">--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="layui-collapse">--%>
                    <%--<div id="content1" style="display: none">--%>
                        <%--<div class="layui-colla-item">--%>
                            <%--<div class="layui-colla-title">面料</div>--%>
                            <%--<div class="layui-colla-content">--%>
                                <%--<table id="demo" lay-filter="test"></table>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <%--<div id="content2" style="display: none">--%>
                        <%--<div class="layui-colla-item">--%>
                            <%--<div class="layui-colla-title">羽绒</div>--%>
                            <%--<div class="layui-colla-content">--%>
                                <%--<table id="demo1" lay-filter="test"></table>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <%--<div id="content3" style="display: none">--%>
                        <%--<div class="layui-colla-item">--%>
                            <%--<div class="layui-colla-title">毛领</div>--%>
                            <%--<div class="layui-colla-content">--%>
                                <%--<table id="demo2" lay-filter="test"></table>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <%--<div id="content4" style="display: none">--%>
                        <%--<div class="layui-colla-item">--%>
                            <%--<div class="layui-colla-title">棉</div>--%>
                            <%--<div class="layui-colla-content">--%>
                                <%--<table id="demo3" lay-filter="test"></table>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <%--<div id="content5" style="display: none">--%>
                        <%--<div class="layui-colla-item">--%>
                            <%--<div class="layui-colla-title">辅料</div>--%>
                            <%--<div class="layui-colla-content">--%>
                                <%--<table id="demo4" lay-filter="test"></table>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <%--<div id="content6" style="display: none">--%>
                        <%--<div class="layui-colla-item">--%>
                            <%--<div class="layui-colla-title">标准辅料</div>--%>
                            <%--<div class="layui-colla-content">--%>
                                <%--<table id="demo5" lay-filter="test"></table>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                <%--</div>--%>
            <%--</form>--%>
            <%--费用表格--%>
            <form action="" id="form-fee">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>费用</legend>
            </fieldset>
            <div class="layui-form-item">
                <div class="layui-form" action="form.html">
                    <div class="layui-inline">
                        <label class="layui-form-label">水洗费</label>
                        <div class="layui-input-inline"><input type="text" name="waterFee" lay-verify="required" placeholder="水洗费" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">刺绣费</label>
                        <div class="layui-input-inline"><input type="text" name="stitchworkFee" lay-verify="required" placeholder="刺绣费" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">印花费</label>
                        <div class="layui-input-inline"><input type="text" name="printingFee" lay-verify="required" placeholder="印花费" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">配饰费</label>
                        <div class="layui-input-inline"><input type="text" name="accessoriesFee" lay-verify="required" placeholder="配饰费" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">钉珠费</label>
                        <div class="layui-input-inline"><input type="text" name="beadingFee" lay-verify="required" placeholder="钉珠费" class="layui-input">
                        </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">其他1</label>
                        <div class="layui-input-inline"><input type="text" name="other1" lay-verify="required" placeholder="其他1" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">其他2</label>
                        <div class="layui-input-inline"><input type="text" name="other2" lay-verify="required" placeholder="其他2" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">其他3</label>
                        <div class="layui-input-inline"><input type="text" name="other3" lay-verify="required" placeholder="其他3" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">其他4</label>
                        <div class="layui-input-inline"><input type="text" name="other4" lay-verify="required" placeholder="其他4" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">纸箱</label>
                        <div class="layui-input-inline"><input type="text" name="boxCount" lay-verify="required" placeholder="纸箱" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">运费</label>
                        <div class="layui-input-inline"><input type="text" name="freight" lay-verify="required" placeholder="运费" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">税率%</label>
                        <div class="layui-input-inline"><input type="text" name="tax" lay-verify="required" placeholder="税率" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">是否含税</label>
                        <input type="radio" name="isTax" value="0" title="默认" checked="checked">
                        <div lay-radio>
                            <span style="color: blue;">是</span>
                        </div>
                        <input type="radio" name="isTax" value="1" title="默认">
                        <div lay-radio>
                            <span style="color: pink;">否</span>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">单箱运费</label>
                        <div class="layui-input-inline"><input type="text" name="boxFreight" lay-verify="required" placeholder="单箱运费" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">纸箱价格</label>
                        <div class="layui-input-inline"><input type="text" name="boxFee" lay-verify="required" placeholder="纸箱价格" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
                </div>
            </div>
    </form>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn"  onclick="addQuotation()">确定</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="resetBtn">重置</button>
            </div>
        </div>
    </div>
    </body>
    <%--复选框点击--%>
    <%--添加--%>

    <script type="text/javascript">

        let isOk=0;
        function addQuotation() {
                addVerifyPriceForm()
        }

        //报价单判空+添加
        function addVerifyPriceForm() {
            event.preventDefault();
            let styleNumberId = $('[name=styleNumberId]').val()
            let styleNumber = $('[name=styleNumber]').val()
            let item_number = $('[name=itemNumber]').val();
            let brand = $('[name=brand]').val();
            let order_number = $('[name=orderNumber]').val();
            let predict_reorder = $('[name=predictReorder]').val();
            let production_cycle = $('[name=productionCycle]').val();
            let quotation_factory = $('[name=quotationFactory]').val();
            let waterFee = $('[name=waterFee]').val()
            let stitchworkFee = $('[name=stitchworkFee]').val()
            let printingFee = $('[name=printingFee]').val()
            let accessoriesFee = $('[name=accessoriesFee]').val()
            let beadingFee = $('[name=beadingFee]').val()
            let boxCount = $('[name=boxCount]').val()
            let freight = $('[name=freight]').val()
            let tax = $('[name=tax]').val()
            let boxFee = $('[name=boxFee]').val()
            let boxFreight = $('[name=boxFreight]').val()


            // alert(quotation_factory)

            if (styleNumber==-1) {
                alert('款号不能为空')
                return false;
            }
            if (isNullOrEmpty(item_number)) {
                alert('货号不能为空')
                return false;
            }
            // if (isNullOrEmpty(brand)) {
            //     alert('品牌不能为空')
            //     return false;
            // }
            if (isNullOrEmpty(order_number)) {
                alert('合同数量不能为空')
                return false;
            }
            if (isNullOrEmpty(predict_reorder)) {
                alert('预计返回件数不能为空')
                return false;
            }
            if (isNullOrEmpty(production_cycle)) {
                alert('生产周期不能为空')
                return false;
            }

            if (isNullOrEmpty(waterFee)) {
                alert('水洗费不能为空')
                return false;
            }
            if (isNullOrEmpty(stitchworkFee)) {
                alert('刺绣费不能为空')
                return false;
            }
            if (isNullOrEmpty(printingFee)) {
                alert('印花费不能为空')
                return false;
            }
            if (isNullOrEmpty(accessoriesFee)) {
                alert('配饰费不能为空')
                return false;
            }
            if (isNullOrEmpty(beadingFee)) {
                alert('钉珠费不能为空')
                return false;
            }
            if (isNullOrEmpty(boxCount)) {
                alert('纸箱数量不能为空')
                return false;
            }
            if (isNullOrEmpty(freight)) {
                alert('运费不能为空')
                return false;
            }


            if ( $('[name=isTax]:checked').val()==0){
                if (isNullOrEmpty(tax)) {
                    alert('税率不能为空')
                    return false;
                }
            }
            if (isNullOrEmpty(boxFee)) {
                alert('纸箱价格不能为空')
                return false;
            }
            if (isNullOrEmpty(boxFreight)) {
                alert('纸箱运费不能为空')
                return false;
            }

            let data ={};
            let value = $('#form-verifyPrice').serializeArray();
            $.each(value, function (index,item) {
                data[item.name] = item.value;
            });
            let verifyPrice = JSON.stringify(data);
            console.log(verifyPrice)
            $.ajax( {
                "url"            :  "quotationManager/verifyPriceAdd",                      // 要提交的URL路径
                "type"         :  "post",                     // 发送请求的方式
                "data"         :  verifyPrice,                      // 要发送到服务器的数据
                "dataType" :  "text",                   // 期望接受的数据格式
                "contentType":"application/json;charset=utf-8;",
                "success"  :  function(result) {  // 请求成功后要执行的代码
                    // console.log(result);
                    if(result=="success"){
                        addFee()
                        alert("报价单添加成功");

                        // window.location.href="tosearch";
                    }else{
                        alert("新增失败");
                    }
                },
                "error"       :  function() {           // 请求失败后要执行的代码
                    alert("添加出错了！")
                }
            } );

        }
        //费用添加
        function addFee() {
            let data2 ={};
            let value2 = $('#form-fee').serializeArray();
            $.each(value2, function (index,item) {
                data2[item.name] = item.value;
            });
            let fee = JSON.stringify(data2);
            let styleNumberId = $('[name=styleNumberId]').val();
            console.log(fee)
            $.ajax( {
                "url"            :  "quotationManager/feeAdd?styleNumberId="+styleNumberId,                      // 要提交的URL路径
                "type"         :  "post",                     // 发送请求的方式
                "data"         :  fee,                      // 要发送到服务器的数据
                "dataType" :  "text",                   // 期望接受的数据格式
                "contentType":"application/json;charset=utf-8;",
                "success"  :  function(result) {  // 请求成功后要执行的代码
                    // console.log(result);
                    if(result=="success"){
                        alert("添加费用成功");
                        window.location.href="toQuotationList";
                    }else{
                        alert("新增费用失败");
                    }
                },
                "error"       :  function() {           // 请求失败后要执行的代码
                    alert("费用添加出错了！")
                }
            } );
        }
        //判空开始！
        function isNullOrEmpty(str) {
            if (str == null || str==""){
                return true
            }else {
                return false
            }
        }
    </script>

  <%--  &lt;%&ndash;重置按钮&ndash;%&gt;
    <script src="https://cdn.staticfile.org/layui/2.5.7/layui.js"></script>
    <script>
        layui.use('form', function () {
            var form = layui.form;
            // 监听重置按钮点击事件
            document.getElementById('resetBtn').addEventListener('click', function () {
                form.render(null, 'form-verifyPrice'); // 重置表单
            });
        });

    </script>--%>

    <%--渲染款号--%>
    <script>
        $.ajax({
            url: "quotationManager/getAllStyleNumber", // 后端 Controller 的请求路径
            type: "GET",
            success: function (data) {
                var dropdownData = data; // 获取到的下拉框数据

                var select = document.getElementById("styleNumber");
                for (var i = 0; i < dropdownData.length; i++) {
                    var option = document.createElement("option");
                    option.text = dropdownData[i].styleNumber;
                    option.value = dropdownData[i].styleNumberId;
                    select.appendChild(option);
                }

                layui.use('form', function(){
                    var form = layui.form;
                    form.render('select'); // 渲染下拉框

                    form.on('select(styleNumber)', function(data){
                        var selectedValue = data.value; // 获取选中的值
                        $('[name=styleNumberId]').val(selectedValue); // 将选中的值保存到隐藏的 input 标签中
                        // document.getElementById('styleNumberId').value = selectedValue;
                       // let style = $('[name=styleNumberId]').val();
                       // alert(selectedValue)

                        // 发送请求，查询相关数据
                        $.ajax({
                            url: 'quotationManager/getBrandByStyleNumber',
                            type: 'GET',
                            data: {styleNumberId: selectedValue},
                            dataType: 'json',
                            success: function(data) {
                                console.log(data)
                                // 将查询结果显示在输入框中
                                // $('#contactName').val(data.contactName);
                                // 遍历数组，获取每个元素的contactName值
                                if(data==-1){
                                    $('[name=brand]').val('品牌');
                                }else {
                                    for (var i = 0; i < data.length; i++) {
                                        var brand = data[i].brand;
                                       // alert(brand);
                                        // 将contactName值显示在输入框中
                                        $('[name=brand]').val(brand);
                                    }
                                }

                            },
                            error:function () {
                                alert("没有改品牌")
                            }
                        });
                    });
                });
            }
        });
    </script>
    </html>
